package com.xin.core
{
	import com.xin.components.base.LiteSprite;
	import com.xin.mvc.IView;
	import com.xin.mvc.message.MessageEvent;
	import com.xin.mvc.message.MessageFacade;

	import flash.events.Event;

	/**
	 * 视图基类, 实现消息机制
	 * @author xin
	 */
	public class View extends LiteSprite implements IView
	{
		public function View(w : int, h : int)
		{
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
			
			super(w, h);
		}

		private function onAddedToStage(event : Event) : void
		{
			for each(var msg:String in listInterestMessages())
			{
				MessageFacade.getInstance().addMessageListener(msg, handleMessage);
			}
		}
		
		private function onRemovedFromStage(event : Event) : void
		{
			for each(var msg:String in listInterestMessages())
			{
				MessageFacade.getInstance().removeMessageListener(msg, handleMessage);
			}
		}
		
		/**
		 * 侦听的消息
		 */
		public function listInterestMessages():Array
		{
			return [];
		}
		
		/**
		 * 处理侦听的消息
		 */
		public function handleMessage(e:MessageEvent):void{};
	}
}
